package praca.framework;

import android.util.Log;

public class FPSCounter {
	
	long startTime = System.nanoTime();
	int frames = 0;
	int i = 0;
	int NR = 20;
	int[] results = new int[NR];
	
	
	public void logFrame() {
		frames++;
		if(System.nanoTime() - startTime >= 1000000000) {
			Log.d("FPSCounter", "fps: " + frames);
			frames = 0;
			startTime = System.nanoTime();
		}
	}
	
	public void logFrame2() {
		frames++;
		if(System.nanoTime() - startTime >= 1000000000) {
			if(i < NR){
				Log.d("FPSCounter", "fps: " + frames);
				results[i++] = frames;
			}else{
				i = 0;
				int suma = 0;
				for(int j = 0; j < NR; j++){
					suma = suma + results[j];
				}
				suma = suma / NR;
				Log.d("FPSCounter", "Koniec. Srednia liczba ramek: "+suma);	
			}
			
			frames = 0;
			startTime = System.nanoTime();
		}
	}
}
